package com.ckx.test.dir;

import org.apache.commons.io.IOUtils;
import org.dromara.hutool.core.io.IoUtil;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;

public class RenameDir {

    public static void main(String[] args) throws Exception {

        var pathList = new ArrayList<Path>();

        Files.walkFileTree(Path.of("D:\\code\\idea\\ckx-cloud-framework"), new SimpleFileVisitor<>(){
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                String absolutePath = dir.toFile().getAbsolutePath();
                if (absolutePath.endsWith("rc\\main\\java\\com\\fc\\cloud")) {
                    pathList.add(dir);
                    System.out.println(absolutePath);
                }
                return super.preVisitDirectory(dir, attrs);
            }
        });


        pathList.forEach(path -> {
            File file = path.toFile();
            String absolutePath = file.getAbsolutePath();
            boolean b = file.renameTo(new File(absolutePath.replace("fc", "ckx")));
            System.out.println(b);
        });

    }
}
